/*
 * BitFont - the first bitmapped font, based on the big-png system.
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package flash3f;

import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;
import StringTools;
//import flash3f.Images;

class BitFont
// Mappings are based on ASCII.
// we hardcode an offset where the encodings begin.
// Class is not instantiated, it just returns bitmapdatas.
{

	private static var offset : Int = 0xABCD00;
	public static var height : Int = 26;
	
	static public function gen(input : Array<Dynamic>) : BitmapData
	{
		var imagelist : Array <Int> = new Array();
		var poslist : Array <Point> = new Array();
		var curpos : Float = 0;
	
		var text : String = "";
		
		for (i in input)
		{
			text += Std.string(i);
		}
		
		for (c in 0...text.length)
		{
			var code = offset + text.charCodeAt(c);
			if (Images.data.exists(code))
			{
				imagelist.push(code);
				poslist.push(new Point(curpos, 0));
				curpos += Images.getdata(code).width;
			}
			else if (text.charAt(c)==" ")
			{
				curpos += 9;
			}
		}
		
		return Images.composenew(Std.int(curpos), height, imagelist, poslist);
	}
	
}
